package com.cosina.game;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;

public class GameSelectActivity extends Activity {

	private Gallery gameEntryGallery;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.gameselect);
		Gallery gameEntryGallery = (Gallery)findViewById(R.id.gamesEntryGallery);
		gameEntryGallery.setAdapter(new ImageAdapter(this));
		gameEntryGallery.setOnItemClickListener(new OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				if(position == 2){
					Intent intent = new Intent(GameSelectActivity.this,BallGameStartActivity.class);
					startActivity(intent);
				}
			}});
	}

	
	public class ImageAdapter extends BaseAdapter{
		private Context myContext;
		
		public ImageAdapter(Context context){
			this.myContext = context;
		}
		
		private int[] myImageIds = {
				R.drawable.blue,
				R.drawable.yellow,
				R.drawable.green,
				R.drawable.purple,
				R.drawable.red,
		};
		@Override
		public int getCount() {
			return myImageIds.length;
		}
		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return myImageIds[position];
		}
		@Override
		public long getItemId(int position) {
			return position;
		}
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ImageView i = new ImageView(this.myContext);
			i.setImageResource(myImageIds[position]);
			i.setScaleType(ImageView.ScaleType.FIT_XY);
			i.setLayoutParams(new Gallery.LayoutParams(120,120));
			return i;
		}
		
		public float getScale(boolean focused, int offset){
			if(focused)
				return 1.2f;
			else 
				return 1f;
		}
	}
}
